package com.example.demo.repository;

import com.example.demo.pojo.Account;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

public interface AccountRepository extends JpaRepository<Account, Integer> {

    @Query(value = "select * from account where username = ?1 and is_delete = 0", nativeQuery = true)
    Account findAccountsByUsername(String username);

    @Query(value = "select * from account where username = ?1 and password = ?2 and is_delete = 0", nativeQuery = true)
    Account findAccountByUsernameAndPassword(String username, String password);

    @Query(value = "update account set password = ?1 where username = ?2", nativeQuery = true)
    @Modifying
    void updatePasswordByUsername(String password, String username);

    @Query(value = "select * from account where username = ?1 and email = ?2 and is_delete = 0", nativeQuery = true)
    Account findAccountByUsernameAndEmail(String username, String email);

}
